import 'package:example/app/data/model/article_bean.dart';
import 'package:example/app/data/repository/wan_android_repository.dart';
import 'package:flutter_base_framework/flutter_base_framework.dart';

class FavouriteController extends BaseViewModel {

  collect(ArticleBean article) async {
    setBusy();
    try {
      // article.collect 字段为null,代表是从我的收藏页面进入的 需要调用特殊的取消接口
      if (article.collect == null) {
        await WanAndroidRepository.unMyCollect(
            id: article.id, originId: article.originId);
      } else {
        if (article.collect!) {
          await WanAndroidRepository.unCollect(article.id);
        } else {
          await WanAndroidRepository.collect(article.id);
        }
      }
      article.collect = !(article.collect ?? true);
      setIdle();
    } catch (e, s) {
      var error = handlerError(e, s);
      showToast(error.message!);
      setError();
    }
  }

}